import React, { Component } from 'react'
import { Button, Text, TextInput, View } from 'react-native'

export default class StuAddor extends Component {
    state={stu:{}}
    _nameChange=name=>{
        let stu=this.state.stu
        stu.name=name
        this.setState({stu})
    }
    _update=()=>{
        fetch("http://172.20.10.2:3000/stus",{method:"POST",
        headers:{'Content-Type':'application/json'},
        body:JSON.stringify(this.state.stu)})
        .then(resp=>resp.json())
        .then(user=>{
            console.log(user)
            this.props.navigation.navigate("Home")
        })
    }
    render() {
        return (
            <View>
                <TextInput value={this.state.stu.name} 
                onChangeText={this._nameChange}/>
                <Button title="更新" onPress={this._update}/>
            </View>
        )
    }
}
